package com.fzkj.juc.forkjoin;

import com.fzkj.juc.forkjoin.entity.User;
import com.fzkj.juc.forkjoin.forkjoin2.UserRepeatRecursiveTask;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ForkJoinPool;

/**
 * @ description    用fork/join框架实现任务的拆分
 * @ author yaya
 * @ since 2024/9/5
 */
public class ForkJoinApp {

    public static void main(String[] args) {
//        ForkJoinPool forkJoinPool = new ForkJoinPool();
//        URecursiveTask task = new URecursiveTask(1, 100000);
//        Long result = forkJoinPool.invoke(task);
//        System.out.println(result);

        // 对user去重
        List<User> usrList = new ArrayList<>();
        usrList.add(new User(1, "1", "1"));
        usrList.add(new User(2, "2", "2"));
        usrList.add(new User(3, "3", "3"));
        usrList.add(new User(4, "4", "4"));
        usrList.add(new User(5, "5", "5"));

        ForkJoinPool forkJoinPool = new ForkJoinPool();
        UserRepeatRecursiveTask task = new UserRepeatRecursiveTask(usrList);
        Boolean result = forkJoinPool.invoke(task);
        System.out.println(result);
    }
}
